package cn.lger.util;

/**
 * 参数验证工具类
 *
 * @author Pro
 * @date 2018-06-27.
 */
public class ValidateUtil {

    public static final String PHONE_REG = "^\\d{11}$";
    public static final String EMAIL_REG = "^[A-z0-9.\\-_]{1,64}?@(\\w+?(\\.\\w+)+){1,255}?$";
    public static final int MAX_EMAIL_LENGTH = 320;

    private ValidateUtil(){}

    /**
     * 验证邮箱格式是否正确
     * @param email email字符串，要求不为空且部位空字符串
     * @return boolean
     */
    public static boolean isValidEmail(String email){
        return StringEmptyUtil.notEmpty(email)
                && email.length() < MAX_EMAIL_LENGTH
                && email.matches(EMAIL_REG);
    }

    /**
     * 验证电话是否符合格式
     * @param phone 电话号码字符串，要求不为空且部位空字符串
     * @return boolean
     */
    public static boolean isValidPhoneNumber(String phone){
        return phone != null && !"".equals(phone.trim()) &&
                phone.matches(PHONE_REG);
    }
}
